﻿import com.dmotiko.general.*
import com.dmotiko.lib.ScrollerMovie
import com.dmotiko.util.Point
import com.dmotiko.zonaoutlet.*
import mx.transitions.*
import mx.transitions.easing.*
import mx.utils.Delegate

class ZOOutletList
extends SelectorList {
	
	private function initClip():Void {
		super.initClip();
		nColorNormal = 0xCED6DC;
		nColorOver = 0xFFFFFF;
	}
	
	private function refreshData():Void {
		super.refreshData();
		drawList("");
	}
	
	private function showContent():Void {
				
		if ( aList.length == 0) {
			
			hide();
			return;
			
		}
		
		var nY:Number = 0;
		var nDelay:Number = 0;
		var nDelayCount:Number = nDelay;
		var index:Number = 0;
		var clip;
		var selectorList:SelectorList = this;
		mcContent._x = 2;
		mcDragger._y = mcBar._y;
		this.onEnterFrame = function(){
			if(nDelayCount == 0){
				if( index == aList.length ){
					delete this.onEnterFrame;
					selectorList.dispatchEvent( { type: BaseClipEvent.READY, target: selectorList } );
					return;
				}
				nDelayCount = nDelay;
				clip = mcContent.attachMovie("SelectorListItem", "mcItem"+index, index);
				clip.label.text = aList[index].key;
				clip._alpha = 0;
				clip._x = 0;
				clip._y = 0;
				clip.initX = 0;
				clip.data = aList[index];
				clip.colorTween = new TweenRGB(clip, "", Regular.easeOut, selectorList.nColorOver, selectorList.nColorNormal, 1.5, true);
				clip.onRollOver = function(){
					if(this.tween) this.tween.stop();
					this.tween = new Tween(this, "_x", Elastic.easeOut, this._x, this.initX+3, 1.5, true);
					this.colorTween = new TweenRGB(this, "", Regular.easeOut, selectorList.nColorNormal, selectorList.nColorOver, 1.5, true);
				}
				clip.onRollOut = function(){
					if(this.tween) this.tween.stop();
					this.tween = new Tween(this, "_x", Elastic.easeOut, this._x, this.initX, 0.5, true);
					this.colorTween = new TweenRGB(this, "", Regular.easeOut, selectorList.nColorOver, selectorList.nColorNormal, 1.5, true);
				}
				clip.onRelease = function(){
					selectorList.dispatchEvent( { type: BaseClipEvent.CHANGED, target: selectorList, selectedItem: this.data } );
					//selectorList.hide();
				}
				
				/* back tween */
				if ( index == 0 ) {
					var endY:Number = clip._height * aList.length;
					mcBack._height = size.getY();
					if ( endY < mcMask._height ) {
						ScrollerMovie.releaseScroll( mcContent, mcDragger, mcBar );
					} else {
						ScrollerMovie.setScroll( mcContent, mcMask, mcDragger, mcBar );
					}
				}
				
				//this.registerTween( "selectItem"+index+"motion", new Tween( clip, "_y", Elastic.easeOut, clip._y, nY, 1, true) );
				clip._y = nY;
				this.registerTween( "selectItem"+index+"fade", new Tween( clip, "_alpha", Regular.easeOut, clip._alpha, 100, 0.3, true) );
				nY += clip._height;
				index ++;
					
			} else {
				nDelayCount --;
			}
		}
	}
	
}